package cn.edu.heuet.bnve.activity.ScheduleActivity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import java.util.List;

import cn.edu.heuet.bnve.R;
import cn.edu.heuet.bnve.databinding.ActivitySetLocalBinding;
import cn.edu.heuet.bnve.utils.LocationUtils;

public class SetLocalActivity extends AppCompatActivity {

    private ActivitySetLocalBinding binding;
    Button getLcationButton;
    EditText edLocation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_with_view_pager);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_set_local);
        initData();
        initView();
        initEvent();
    }


    public static void show(Context context) {
        context.startActivity(new Intent(context, SetLocalActivity.class));
    }

    public void initData(){



    }

    public void initView(){

        getLcationButton = binding.buttonGetLocation;
        edLocation = binding.etxLocation;
    }

    public void initEvent(){
        binding.ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        getLcationButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                List<String> locations = LocationUtils.getInstance().getLocations(SetLocalActivity.this);
                if (locations.size()!= 0){
                    edLocation.setText(locations.get(0));
                }
                for (String s :locations){
                    Log.i("wqs",s);
                }
            }
        });
        binding.txSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent();
                if(edLocation.getText().toString().equals("")){
                    intent.putExtra("local", "无");
                    setResult(2, intent);
                    finish();
                }else {
                    intent.putExtra("local", edLocation.getText().toString());
                    setResult(2, intent);
                    finish();
                }
                finish();
            }
        });
    }









}